package lesson6.socket.server;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.time.LocalDateTime;

/**
 * 客户端与服务端通讯采用字符串<br/>
 * Created on : 2018-01-28 18:12
 * @author lizebin
 */
public class ServerHandler extends SimpleChannelInboundHandler<String> {

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
		Thread.sleep(1000);
		System.out.println("remote address:" + ctx.channel().remoteAddress());
		ctx.channel().writeAndFlush("from server:" + LocalDateTime.now());
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		cause.printStackTrace();
		ctx.close();
	}
}
